<!DOCTYPE html>
<html lang="en">
<head>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<body>
    <a href="/views/register.html">注册</a>
    <form id="registerForm">
        <p>用户名<input name="username"></p>
        <p>密码<input name="password"></p>
        <p><input type="button" value="登录" id="btn"> </p>
    </form>
<script>
 $("#btn").click(function (){
     $.ajax({
         url:'/user/login',
         data:$("#registerForm").serialize(),
         dataType:'json',
         success:function (data){
             console.log(data)
             //如果失败
             if(data.code==40000){
                 alert(data.massage)
             }
             //成功后跳转到主页
             if(data.code==20000){
                 location.href='/views/main.html';
             }
         }
     });
 });
</script>
</body>
</html>